import Vue from "vue";
import Vuex from "vuex"
Vue.use(Vuex)
import axios from 'axios'

import classObj from './modules/classObj'
import user from './modules/user'
import book from './modules/books'
import getBooks from "./modules/getBook";

const store = new Vuex.Store({
    state: {
        name:'jony',
        age:25
        // class: 'web67',
        // userInfo: {
        //     name: 'tom',
        //     skills: ['抖音', 'B站', '美团'],
        //     address: '武汉黑马',
        //     logo: 'https://vuejs.org/images/logo.svg'
        //     //  https://www.runoob.com/wp-content/uploads/2016/02/react.png
        // },

        // books: [],

        // newBooks: [
        //     {
        //         "name": "javasript技术内幕",
        //         "price": 100,
        //         "img": "https://img3m7.ddimg.cn/64/26/29120617-1_u_8.jpg"
        //     },
        //     {
        //         "name": "数学之美",
        //         "price": 44,
        //         "img": "https://img3m2.ddimg.cn/18/30/28538352-1_b_5.jpg"
        //     },
        //     {
        //         "name": "认知天性",
        //         "price": 40,
        //         "img": "https://img3m3.ddimg.cn/74/33/1732997153-3_u_3.jpg"
        //     }
        // ]
    },
    mutations: {
        setName(state){
            state.name = 'tom'
        }
        // changeLogo: function (state, { newLogo, second, uname }) {
        //     state.userInfo.logo = newLogo
        //     console.log(second);
        //     state.userInfo.name = uname
        //     console.log(state.userInfo.name);
        // },
        // setBooks(state, newBooks) {
        //     state.books = newBooks
        // }
    },
    getters: {
        gAge(state){
            return state.age+2
        }
        // sum(state) {
        //     /*reduce(函数【函数的参数：累加值，数组的每一项】，初始值)   ===》返回的是total或者是累加值  */
        //     // return state.newBooks.reduce((total,item)=>{
        //     //   return total+=item.price
        //     // },0)
        //     return state.newBooks.reduce((total, item) => total + item.price, 0)

        // }
    },
    actions: {
        aSet(context,m){
            var n=1
            setInterval(() => {
              n+=m
              console.log(n);
            }, 500);
          }
        // async AgetBooks(context){
        //   const res = await axios(
        //   'https://www.fastmock.site/mock/37d3b9f13a48d528a9339fbed1b81bd5/book/api/books'
        // )
        // /* 触发mutations中的函数 */
        // context.commit('setBooks',res.data.data)
        // }
        // async AgetBooks({ commit }) {
        //     const res = await axios({
        //         url: 'https://www.fastmock.site/mock/37d3b9f13a48d528a9339fbed1b81bd5/book/api/books'
        //     })
        //     commit('setBooks', res.data.data)
        // }


    },
    modules:{
        classObj,
        user,
        book,
        getBooks
      }
})

export default store